<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="开始用药时间">
            <el-date-picker v-model="form.startDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结束用药时间">
            <el-date-picker v-model="form.endDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用药天数">
            <el-input v-model="form.days" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用法">
            <el-input v-model="form.useMethod" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="每次服用（粒）">
            <el-input v-model="form.take" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="每次剂量（mg）">
            <el-input v-model="form.dose" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="当日服药剂量（mg）">
            <el-input v-model="form.doseToday" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="目前总服药剂量">
            <el-input v-model="form.doseTotal" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="起效时间">
            <el-date-picker v-model="form.onsetDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="副作用">
            <el-checkbox-group v-model="form.sideEffect">
              <el-checkbox label="1">无</el-checkbox>
              <el-checkbox label="2">肝功能异常</el-checkbox>
              <el-checkbox label="3">肾功能异常</el-checkbox>
              <el-checkbox label="4">血常规异常</el-checkbox>
              <el-checkbox label="5">其他</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="是否停药">
            <el-radio-group v-model="form.stopState">
              <el-radio :label="1">否</el-radio>
              <el-radio :label="2">是</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="治疗情况">
            <el-input v-model="form.treatmentDetails" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="基因">
            <el-input v-model="form.gene" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="抑制位置">
            <el-input v-model="form.suppressionPosition" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="基因型">
            <el-input v-model="form.genotype" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="ID" />
        <el-table-column prop="startDate" label="开始用药时间" />
        <el-table-column prop="endDate" label="结束用药时间" />
        <el-table-column prop="days" label="用药天数" />
        <el-table-column prop="useMethod" label="用法" />
        <el-table-column prop="dose" label="每次剂量（mg）" />
        <el-table-column prop="doseToday" label="当日服药剂量（mg）" />
        <el-table-column v-if="checkPer(['admin','drugDetails2:edit','drugDetails2:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDrugDetails2 from '@/api/drugDetails2'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, pId: '', dId: 4, startDate: null, endDate: null, days: null, useMethod: null, onsetDate: null, sideEffect: null, stopState: null, reason: null, aggravateState: null, treatmentDetails: null, gene: null, suppressionPosition: null, genotype: null, take: null, dose: null, doseToday: null, doseTotal: null, improve: null, abnormalDescribe: null, sideEffectAbnormalIndex: null, taCheck: null, taTreatment: null, taConcentration: null, taDetectionDate: null, taTakeWu: null, taTakeWuDose: null, taTakeWuEffectiveTime: null, taTakeWuCd: null }
export default {
  name: 'DrugDetails2',
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '硫唑嘌呤用药治疗记录', url: 'api/drugDetails2', query: { }, idField: 'id', sort: 'id,desc', crudMethod: { ...crudDrugDetails2 }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'drugDetails2:add'],
        edit: ['admin', 'drugDetails2:edit'],
        del: ['admin', 'drugDetails2:del']
      },
      rules: {
        pId: [
          { required: true, message: 'pID不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'pId', display_name: 'pID' },
        { key: 'dId', display_name: '药编号' }
      ],
      gene: [{
        value: '1',
        label: 'ABCB1'
      }],
      suppressionPosition: [{
        value: '1',
        label: 'rs1045642'
      }],
      genotype: [{
        value: '1',
        label: 'AA'
      }, {
        value: '2',
        label: 'AG'
      }, {
        value: '3',
        label: 'GG'
      }],
      pId: this._routerRoot._routerRoot._route.query.id
    }
  },
  created() {
    defaultForm.pId = this.pId
    this.crud.query.pId = this.pId
    this.crud.query.dId = 4
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.query.pId = this.pId
      this.crud.query.dId = 4
      return true
    }
  }
}
</script>

<style scoped>

</style>
